<!--导航条组件-->
<template>
  <el-affix>
    <header class="nav">
      <div class="nav-content">
        <!--                导航栏左边logo-->
        <div class="nav-left">
        </div>
        <!--                中间部分-->
        <div class="nav-middle">
          <ul class="nav-module">
            <li class="nav-list" v-for="item in navigations">
              <a class="nav-link" :class="{'nav-now':route.path===item.key}" href="javascript:void(0)" @click="changePage(item.key)">{{item.value}}</a>
            </li>
          </ul>
        </div>
        <!--                右边部分-->
        <div class="nav-right">
          <ul class="nav-module-2">
            <li class="nav-list nav-7">
              <div class="nav-search">
                <input class="nav-search-frame" type="text" placeholder="搜索">
                <div class="nav-svg nav-search-svg"></div>
              </div>
            </li>
            <!--                        这里给头像图片留了一个list大小的位置，防止position后组件重叠-->
            <li class="nav-list nav-8">
            </li>
            <li class="nav-list nav-9" v-if="user_store.isLogin">
              <div class="nav-notice">
                <div class="notice-svg"></div>
                <div class="notice-text">通知</div>
              </div>
            </li>
            <li class="nav-list nav-9" v-if="!user_store.isLogin">
              <a class="nav-link" href="javascript:void(0)" @click="showLogin">登录</a>
            </li>
            <li class="nav-list nav-9" v-if="!user_store.isLogin">
              <a class="nav-link" href="#">注册</a>
            </li>
          </ul>

        </div>

      </div>
      <!--            这里是头像图片部分以及悬停头像展开栏-->
      <div class="nav-photo" v-if="user_store.isLogin" :style="{'background-image':avatar}"></div>
      <div class="nav-photo-unfold">

        <div class="nav-unfold-name">{{ user_store.getLoginUserInfo().nickname }}</div>
        <div class="nav-unfold-identity">入党积极分子</div>

        <!--                展开栏主要内容-->
        <div class="nav-unfold-content">
          <ul class="nav-content-module">
            <li class="nav-content-list">
              <!--                        利用nav-content-svg类名，给svg设置相同属性-->
              <div class="nav-content-svg individual-svg"></div>
              <div class="nav-content-text">个人中心</div>
              <div> ></div>
            </li>
            <li class="nav-content-list">
              <div class="nav-content-svg activity-svg"></div>
              <div class="nav-content-text">我的活动</div>
              <div> ></div>
            </li>
            <li class="nav-content-list">
              <div class="nav-content-svg collect-3-svg"></div>
              <div class="nav-content-text">我的收藏</div>
              <div> ></div>
            </li>
            <li class="nav-content-list">
              <div class="nav-content-svg report-svg"></div>
              <div class="nav-content-text">思想汇报</div>
              <div> ></div>
            </li>
            <li class="nav-content-list">
              <div class="nav-content-svg locus-svg"></div>
              <div class="nav-content-text">成长轨迹</div>
              <div> ></div>
            </li>
            <li class="nav-content-list">
              <div class="nav-content-svg money-svg"></div>
              <div class="nav-content-text">党费缴纳</div>
              <div> ></div>
            </li>
            <li class="nav-content-list">
              <div class="nav-content-svg exit-svg"></div>
              <div class="nav-content-text">退出</div>
            </li>
          </ul>


        </div>
      </div>
    </header>
  </el-affix>


</template>

<script setup>
import {ref} from "vue";
import {pageStore} from "../../store/page.js";
import {userStore} from "../../store/userState.js";
import {useRoute, useRouter} from "vue-router";

const router = useRouter()
const route = useRoute()

console.log(route.path);

const pageStatus = pageStore()

const user_store = userStore()

const navigations = [
  {
    key: "/",
    value: "首页"
  },
  {
    key: "/theory",
    value: "党建"
  },
  {
    key: "/periodical",
    value: "期刊"
  },
]

// 拼接用户头像src地址
const avatar = ref(`url(${user_store.getLoginUserInfo().avatar})`)

const changePage = (name) => {
  console.log(name);
  router.push({
    path: name
  })
}

// 打开登录界面
const showLogin = () => {
  console.log("login click");
  pageStatus.setLoginPageStatus(true)
}


</script>

<style scoped>
/*导航栏模块*/
.nav {
  width: 100%;
  padding: 0rem;
  height: 7rem;
  /*color:rgba(255, 235, 59, 1);*/
  color: rgba(156, 0, 0, 1);
  font-size: 1.8rem;
  font-family: "黑体";
  box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid #fff;
  font-weight: bolder;
  background-color: white;
  /*border-bottom: 0.5rem solid rgba(156, 0, 0, 1);*/
}

.nav-content {
  display: flex;
  line-height: 7rem;
  /*align-content: center;*/
  justify-content: space-around;
  /*background-color: rgba(156, 0, 0, 1);*/
}

.nav-left {
  width: 12%;
  height: 7rem;
  text-align: center;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  margin-left: 2rem;
}

.nav-logo {
  background-color: yellow;
  /*width:4rem;*/
}

.nav-middle {
  flex: 1;
  margin-left: 1rem;
}

.nav-right {
  width: 50%;
  margin: 0 auto;
  margin-left: 5rem;
  /*background-color: lightskyblue;*/
}

.nav-module, .nav-module-2 {
  width: 100%;
  height: 100%;
  display: flex;
  /*justify-content:space-around;*/
}

.nav-module-2 {
}

.nav-list {
  width: 9rem;
  list-style: none;
  text-align: center;
}

.nav-link {
  height: 80%;
  color: black;
  letter-spacing: 2px;
  padding-bottom: 2.5rem;
  text-decoration: none;
  font-weight: normal;
}

.nav-now {
  color: rgba(156, 0, 0, 1);
  font-weight: bolder;
  border-bottom: 5px solid rgba(156, 0, 0, 1);
}

/*.nav-link:hover{*/
/*    color:rgba(156, 0, 0, 1);*/
/*}*/
.nav-search {
  width: 33rem;
  position: relative;
}

.nav-search-frame {
  width: 30rem;
  height: 3rem;
  margin-top: 2rem;
  border-radius: 20px;
  padding-left: 1rem;
  border: 1px solid rgba(128, 128, 128, 1);
}

.nav-search-frame:focus {
  border: none;
  outline: none;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(128, 128, 128, 1);

}

.nav-svg {
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  background-size: 2rem 2rem;
  background-position: center;
  background-repeat: no-repeat;
}

.nav-search-svg {
  right: 3rem;
  top: 2.5rem;

  position: absolute;
}

.nav-notice {
  width: 100%;
  height: 100%;
  position: relative;
  /*padding-top: 2rem;*/
}

.notice-svg {
  position: absolute;
  cursor: pointer;
  width: 2.5rem;
  height: 2.5rem;
  background-size: 2.5rem 2.5rem;
  background-position: center;
  background-repeat: no-repeat;
  top: 1.8rem;
  left: 0;
}

.notice-text {
  letter-spacing: 0;
  position: absolute;
  top: 1.7rem;
  left: 0.3rem;
  font-size: 1rem;
  color: rgba(128, 128, 128, 1);
}

.nav-8 {
  margin-left: 23rem;
  margin-right: 2rem;
}

.nav-photo {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  margin-top: 1.5rem;
  margin-left: 2rem;
  transition: 0.5s;
  position: absolute;
  z-index: 6;
  left: 120rem;
  top: 0%;
}

.nav-photo:hover {
  transform: scale(1.5) translate(-0.5rem, 1.5rem);
}

.nav-photo-unfold {
  opacity: 0;
  position: absolute;
  left: 111rem;
  top: 7rem;
  /*width:20rem;*/
  /*height:32rem;*/
  background-color: rgba(255, 255, 255, 1);
  box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.25);
  z-index: 5;
  padding: 2rem 4rem 1rem 4rem;
  border-radius: 10px;
  /*pointer-events: none;*/

}

.nav-photo:hover + .nav-photo-unfold {
  animation: appear 0.5s linear forwards;
}

.nav-photo:hover ~ .nav-container {
  opacity: 1;
}

@keyframes appear {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

.nav-unfold-name {
  height: 3rem;
  text-align: center;
  font-size: 1.6rem;
  color: rgba(156, 0, 0, 1);
}

.nav-unfold-identity {
  width: 8rem;
  display: inline-block;
  text-align: center;
  padding: 3px 2px;
  white-space: nowrap;
  letter-spacing: 0.5px;
  background-color: rgba(156, 0, 0, 1);
  /*height:2rem;*/
  color: rgba(255, 255, 255, 1);
  border-radius: 16px;
  font-size: 1rem;
  display: flex;
  justify-content: center;
  margin: 0 auto;
  /*line-height: 0;*/
}

.nav-unfold-content {
  /*background-color: yellow;*/
  color: rgba(128, 128, 128, 1);
}

.nav-content-module {
  margin: 0 auto;
  width: 17rem;
  margin-top: 2rem;
  padding-bottom: 1rem;
  /*border-bottom: 2px solid rgba(229, 229, 229, 1);*/
}

.nav-content-list {
  /*background-color: lightskyblue;*/
  font-size: 1.3rem;
  height: 2.5rem;
  list-style: none;
  display: flex;
  line-height: 2.5rem;
  /*background-color: yellow;*/
  justify-content: space-between;
}

.nav-content-list:not(:first-child) {
  margin-top: 1.2rem;
}

.nav-content-list:last-child {
  justify-content: left;
  padding-top: 1rem;
  border-top: 2px solid rgba(229, 229, 229, 1);
}

.nav-content-list:last-child .nav-content-text {
  margin-left: 1.5rem;
}

.nav-content-svg {
  cursor: pointer;
  width: 2.5rem;
  height: 2.5rem;
  background-size: 2rem 2rem;
  background-position: center;
  background-repeat: no-repeat;
}

.nav-content-text {
  margin-left: -3.5rem;
}

.nav-9 {
  position: relative;
  left: 10rem;
}


</style>
